package com.jackstraw.jack_base.util;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

public class CollectionUtil {


    /**
     * 集合是否为空
     *
     * @return
     */
    public static Boolean isEmpty(Collection collection) {
        if (ObjectUtil.ObjectUtilByLang3.isEmpty(collection) || collection.size() == 0) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    /**
     * 集合是否非空
     *
     * @return
     */
    public static Boolean isNotEmpty(Collection collection) {
        return !isEmpty(collection);
    }


    public static class MapUtil {


        /**
         * 集合是否为空
         *
         * @return
         */
        public static Boolean isEmpty(Map map) {
            return MapUtilByHutool.isEmpty(map);
        }

        /**
         * 集合是否非空
         *
         * @return
         */
        public static Boolean isNotEmpty(Map map) {
            return MapUtilByHutool.isNotEmpty(map);
        }

        /**
         * 获取Map的key，仅当Map只有一条数据
         *
         * @param map
         * @param <T>
         * @param <K>
         * @return
         */
        public static <T, K> T getOne(Map<T, K> map) {
            if (ObjectUtil.ObjectUtilByLang3.isEmpty(map) || map.size() != 1) {
                return null;
            }
            return (T) Arrays.asList(map.keySet()).get(0);

        }


    }

    public static class ListUtil {

    }

    public static class MapUtilByHutool extends cn.hutool.core.map.MapUtil {
    }

    public static class CollectionUtilByHutool extends cn.hutool.core.collection.CollectionUtil {
    }

    public static class ListUtilByHutool extends cn.hutool.core.collection.ListUtil {
    }


}
